<template>
	<view style="padding: 20rpx;">
		<uni-section class="mb-10" title="挂号信息" titleFontSize="28rpx" titleColor="#676767" type="square"></uni-section>
		<view class="box">
			<view class="item">
				<view class="text-left">就诊日期</view>
				<view class="text-right">
					{{appointmentItem.workDate}}&ensp;{{weekDay}}&ensp;{{appointmentItem.dayPart=='0'?'上午':'下午'}}
				</view>
			</view>
			<view class="item">
				<view class="text-left">就诊科室</view>
				<view class="text-right">{{appointmentItem.doctor.department.name}}</view>
			</view>
			<view class="item">
				<view class="text-left">医生姓名</view>
				<view class="text-right">{{appointmentItem.doctor.user.userName}}</view>
			</view>
			<view class="item">
				<view class="text-left">医生职称</view>
				<view class="text-right">{{appointmentItem.doctor.position}}</view>
			</view>
			<view class="item">
				<view class="text-left">挂号费用</view>
				<view class="text-right">{{appointmentItem.doctor.registrationFee}}元</view>
			</view>
		</view>
		<uni-section class="mb-10" style="padding: 10rpx 16rpx;" title="预约须知" titleFontSize="28rpx" titleColor="#676767"
			type="square">
			<text
				style="display: inline-block;margin-top: 30rpx;">请使用本人真实信息预约，根据需要，平台将会进行电话回访。若不能联系您，有权强制取消您的预约并纳入黑名单。谢谢合作。
				用户预约成功，未按时取号就诊累计达3次（含3次，医院停诊与提前取消预约除外）将纳入黑名单，黑名单用户6个月内无法预约挂号！</text>
		</uni-section>
		<button style="margin-top: 80rpx;" type="primary" @click="confirm">确认挂号</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				appointmentItem: {
					doctor: {
						user: {},
						department: {}
					}
				},
				appointmentTimeItem: {},
				weekDay: null,
				order: {
					patientId: uni.getStorageSync('xm-user') ? uni.getStorageSync('xm-user').patientId : null,
					appointmentSchedulerId: null,
					appointmentTime: null,
					type: '0',
					amount: null
				}
			}
		},
		onLoad(option) {
			if (option.params) {
				let appointmentInfo = JSON.parse(decodeURIComponent(option.params));
				this.appointmentItem = appointmentInfo.appointmentItem;
				this.appointmentTimeItem = appointmentInfo.appointmentTimeItem;
				this.weekDay = this.getWeekDay(this.appointmentItem.workDate);
				console.log(appointmentInfo);
			}
		},
		methods: {
			getWeekDay(date) {
				let weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
				return weekDays[new Date(date).getDay()];
			},
			confirm() {
				this.order.appointmentSchedulerId = this.appointmentItem.id;
				this.order.appointmentTime = this.appointmentTimeItem.appointmentTime;
				this.order.amount = this.appointmentItem.doctor.registrationFee;
				this.$request.post('/order/createOrder', this.order).then(res => {
					if (res.code === 200) {
						uni.navigateTo({
							url: '/pages/orders/orders'
						})
						uni.showToast({
							title: '挂号订单已生成，请及时完成支付',
							icon: 'success',
							position: 'top',
						});
					}
				})
			}
		}
	}
</script>

<style>
	.box {
		background-color: #fff;
		font-size: 30rpx;
		font-weight: 500;
		line-height: 75rpx;
		padding: 10rpx 16rpx;
	}

	.item {
		display: flex;
		justify-content: space-between;
	}

	.text-left {
		color: #8b8b8b;
	}

	.text-left {}
</style>